var JS_INTERVIEW = function () {
    var owner = this;
    owner.dom_tag = "interview";
    owner.dom_table = $("#" + owner.dom_tag + "_table");
    owner.currentId = null;
    owner.map_data = {};
    owner.sortName = "interviewTime";
    owner.sortOrder = "desc";
    owner.listBoxDep1 = new Array();
    owner.listBoxDep2 = new Array();
    owner.listBoxInterviewer = new Array();
    owner.listBoxHr = new Array();

    owner.dom_table.datagrid({
        onSortColumn: function (sort, order) {
            owner.sortName = sort;
            owner.sortOrder = order;
            owner.getPage(1);
        }
    }).datagrid("getPager").pagination({
        layout: ["list", "sep", "first", "prev", "sep", "manual", "sep", "next", "last", "refresh", "sep"],
        pageList: [10, 20, 50, 100],
        pageSize: 20,
        buttons: [{
        }],
        onSelectPage: function (pageNum, pageSize) {
            owner.getPage(pageNum, pageSize);
        }
    });

    $("#" + owner.dom_tag + "_search_dep1").combobox({
        onSelect: function (record) {
            owner.loadDep2(record.value, $("#" + owner.dom_tag + "_search_dep2"));
        }
    });

    owner.init = function () {
        $("#" + owner.dom_tag + "_search_dep1").combobox();
        $("#" + owner.dom_tag + "_search_dep2").combobox();
        $("#" + owner.dom_tag + "_search_hr").combobox();
        owner.loadDep1();
        owner.loadUserData();
        owner.getPage(1);
    };

    owner.loadDep1 = function () {
        $.ajax({
            type: "get",
            url: "/dep/getForList",
            cache: false,
            dataType: "json",
            data: {
                level: "1"
            }
        }).done(function (result) {
            if (result.success) {
                for (var key in result.data) {
                    owner.listBoxDep1.push({
                        value: key,
                        text: result.data[key]
                    });
                }
                $("#" + owner.dom_tag + "_search_dep1").combobox("loadData", owner.listBoxDep1);
            } else {
                $.messager.alert("提示信息", result.message);
            }
        });
    };

    owner.loadDep2 = function (father, dom) {
        $.ajax({
            type: "get",
            url: "/dep/getForList",
            cache: false,
            dataType: "json",
            data: {
                level: "2",
                father: father
            }
        }).done(function (result) {
            if (result.success) {
                owner.listBoxDep2 = new Array();
                for (var key in result.data) {
                    owner.listBoxDep2.push({
                        value: key,
                        text: result.data[key]
                    });
                }
                dom.combobox("loadData", owner.listBoxDep2);
            } else {
                $.messager.alert("提示信息", result.message);
            }
        });
    };

    owner.loadUserData = function () {
        $.ajax({
            type: "get",
            url: "/user/getForList",
            cache: false,
            dataType: "json",
            data: {}
        }).done(function (result) {
            if (result.success) {
                for (var i = 0; i < result.data.length; i++) {
                    var obj = result.data[i];
                    if (obj.type == "interviewer") {
                        owner.listBoxInterviewer.push({
                            value: obj.id,
                            text: obj.name
                        });
                    } else {
                        owner.listBoxHr.push({
                            value: obj.id,
                            text: obj.name
                        });
                    }
                }
                $("#" + owner.dom_tag + "_search_hr").combobox("loadData", owner.listBoxHr);
            } else {
                $.messager.alert("提示信息", result.message);
            }
        });
    };

    owner.formatItem = function (obj) {
        var item = {
            "itemId": obj.id,
            "p0": obj.index,
            "p1": obj.name,
            "p2": obj.jobName,
            "p3": obj.interviewTime.date(2),
            "p4": obj.interviewType,
            "p5": obj.workAge,
            "p6": obj.interviewer1,
            "p7": obj.interviewer2,
            "date_create": obj.dateCreate.date(2),
            "p8": owner.generateOpHtml(obj.id)
        };
        return item;
    };

    owner.generateOpHtml = function (id) {
        return "<a class=\"easyui-menubutton\" onmouseover=\"jsInterview.currentId='"+id+"'\" data-options=\"menu:'#"+owner.dom_tag+"_div_op',iconCls:'icon-config'\"></a>";
    };

    owner.getPage = function (pageNum, pageSize) {
        if (pageSize == null) {
            pageSize = owner.dom_table.datagrid("getPager").pagination("options").pageSize;
        }
        var params = {
            "hr": $("#" + owner.dom_tag + "_search_hr").textbox("getValue"),
            "dep1": $("#" + owner.dom_tag + "_search_dep1").combobox("getValue"),
            "dep2": $("#" + owner.dom_tag + "_search_dep2").combobox("getValue"),
            "interviewTime0": $("#" + owner.dom_tag + "_search_interviewTime0").val(),
            "interviewTime1": $("#" + owner.dom_tag + "_search_interviewTime1").val(),
            "pageNum": pageNum,
            "pageSize": pageSize
        };
        $.ajax({
            type: "get",
            url: "/employ/interviewList",
            cache: false,
            dataType: "json",
            data: params
        }).done(function (result) {
            if (result.success) {
                var ps = result.data;
                var data = new Array();
                owner.map_data = {};
                if (ps.size == 0) {
                    $.messager.alert("提示信息", "暂无数据！");
                    return;
                }
                for (var i = 0; i < ps.list.length; i++) {
                    var obj = ps.list[i];
                    obj.index = i+1;
                    owner.map_data[obj.id] = obj;
                    data.push(owner.formatItem(obj));
                }
                owner.dom_table.datagrid("loadData", {
                    "total": ps.total,
                    "rows": data
                });
            } else {
                $.messager.alert("提示信息", result.message);
            }
        }).fail(function () {
            $.messager.alert("提示信息", "网络繁忙，请稍后再试！");
        });
    };

    owner.viewDetail = function () {
        window.open("", "_blank");
    };

    owner.downloadFile = function () {
        window.open("", "_blank");
    };


};